package com.tl.bootmeter.controller;

import com.tl.bootmeter.pojo.WellMode;
import com.tl.bootmeter.service.IWellModeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@Controller
@RequestMapping("wellmode")
public class WellModeController {
    @Autowired
    private IWellModeService wellModeServiceImpl;

    //根据页面传入站id 查询这个站下一共有多少井
    @RequestMapping("selectBystationIdWellMode.do")
    public ModelAndView selectBystationIdWellMode(int station_id){
        System.out.println("进入根据页面传入站id 查询这个站下一共有多少井的控制器");
        System.out.println("页面传入站id="+station_id);
//		List<WellMode> wellModeTable = wellModeServiceImpl.selectBystationIdWellMode(station_id);
        Map<String, Object> stationIdWellModeMap = wellModeServiceImpl.selectBystationIdWellMode(station_id);
        System.out.println(stationIdWellModeMap);
        ModelAndView mo = new ModelAndView();
        mo.addObject("stationIdWellModeMap",stationIdWellModeMap);
        mo.setViewName("well_tables");
        return mo;
    }
    /**
     * 新增油井
     * 增加管区和站的层级后需要把井和站做关联
     * @param wellMode(页面将用户填写的信息封装成一个对象)
     * @return 重新条用selectfindAllWellMode这个方法然后整个页面重新刷新
     */
    @RequestMapping("insertwellMode.do")
    public ModelAndView insertByWellMode(WellMode wellMode,int station_id){
        System.out.println("页面传入的站区id="+station_id+"井号="+wellMode.getWell_namber()+"类型="+wellMode.getWell_type());
        int endwellmode = wellModeServiceImpl.insertByWellMode(wellMode,station_id);
        return selectBystationIdWellMode(station_id);
    }
}
